﻿#include <vector>
#include <opencv2/opencv.hpp>
using namespace cv;



struct InstanceSegmentMap {
    int width = 0, height = 0;      // width % 8 == 0
    unsigned char* data = nullptr;  // is width * height memory

    InstanceSegmentMap(int width, int height);
    virtual ~InstanceSegmentMap();
};

struct Box {
    float left, top, right, bottom, confidence;
    int class_label;
    std::shared_ptr<InstanceSegmentMap> seg;  // valid only in segment task

    Box() = default;
    Box(float left, float top, float right, float bottom, float confidence, int class_label)
        : left(left),
        top(top),
        right(right),
        bottom(bottom),
        confidence(confidence),
        class_label(class_label) {}
};


typedef std::vector<Box> BoxArray;

struct Image {
    const void* bgrptr = nullptr;
    int width = 0, height = 0;

    Image() = default;
    Image(const void* bgrptr, int width, int height) : bgrptr(bgrptr), width(width), height(height) {}
};

class Infer {
public:
    virtual BoxArray forward(const Image& image, void* stream = nullptr) = 0;
    virtual std::vector<BoxArray> forwards(const std::vector<Image>& images,
        void* stream = nullptr) = 0;
};

//class __declspec(dllexport) DL
//{
//public:
//    ~DL();
//    //model_path 模型的地址 
//    //license_path 根据cpu序列号生成的加密文件
//    int loadModel(char* model_path, char* license_path);
//    //image 要预测的图像
//    //BoxArray 预测的结果
//    bool predict(cv::Mat image, BoxArray& result);
//
//private:
//    void* m_model;
//};



class __declspec(dllexport) DL
{
public:
    DL(char* model_path, char* license_path,int mode);
    ~DL();
    bool get_state();
    bool predict(cv::Mat image, BoxArray& result);
private:
    std::shared_ptr<Infer> m_model;
};

class __declspec(dllexport)  DL_New {
public:
    DL* m_dl;
    bool load(char* model_path, char* license_path, int mode);

    void unload();

    bool predict(cv::Mat image, BoxArray& result);

};
